import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { ActivatedRoute } from '@angular/router';
import { defalutImg } from '../comm';
import { CommonService } from '../../../services-common/common.service';
import { PromotionShareService } from '../promotion-share.service';

@Component({
  selector: 'app-divide-game-details',
  templateUrl: './divide-game-details.component.html',
  styleUrls: ['./divide-game-details.component.scss']
})
export class DivideGameDetailsComponent implements OnInit {

  routeParams: any = {};
  detailsData: any = {};

  fallback: string = defalutImg;

  constructor(
    private msg: NzMessageService,
    private activatedRoute: ActivatedRoute,
    private commonService: CommonService,
    private services: PromotionShareService
  ) {
    activatedRoute.queryParams.subscribe((res: any) => {
      this.routeParams = res || {};
    })
  }

  ngOnInit(): void {
    this.loadDetailsData();
  }

  async loadDetailsData() {
    let params = {
      id: this.routeParams.id
    }
    const msgId = this.msg.loading('数据加载中..', { nzDuration: 0 }).messageId;;
    const {code, data, message}: any = await this.services.getAppDetailsData(params);
    this.msg.remove(msgId);

    if (code === 0) {
      this.detailsData = data || {};
      if (data.authDate) {
        let dateArrs = data.authDate.split(',');
        this.detailsData.authDateStr = data.authDate ? `${dateArrs[0]} 至 ${dateArrs[1]}` : '-';
      }
    } else {
      this.msg.error(message);
    }
  }

  copyText(str: any) {
    this.commonService.copyStr(str);
  }
}
